
	/************************************************************************************************
	 	
		Factory:	jsl.Number
						
		Methods:
			obj			Number				(n)								- sid: 3.0
			n				round					(d*)							- sid: 3.0
			n				ceil					(d*)							- sid: 3.0
			n				floor					(d*)							- sid: 3.0
			n				limit					(max, min*)				- sid: 3.0
												
			i				toInteger			()								- sid: 3.0
			b				isInteger			()								- sid: 3.0

		Static:
			n				random				(max*, min*)			- sid: 3.0
			r				degToRad			(d)								- sid: 3.0
			d				radToDeg			(r)								- sid: 3.0

	*************************************************************************************************/

  //-------------------------------------------------------------------------------
	jsl.Number = function(n) {
		try {
	   	var proto, rv
			//@d[    	
      if(arguments.length > 1)	throw jsl.ParamError()//@d]
			
			if(arguments.length) {		
				
				if(n instanceof Number)
					if(n.__augmented) return n
					else							rv = n
				else {
					//@d[
					if(isNaN(n))	throw jsl.ParamError("NaNValue:n")//@d]
					rv = new Number(n)					
				}	
			}
			else
				rv = new Number
															
			proto = jsl.Number.prototype
			
    	for(var id in proto)
    		if(proto.hasOwnProperty(id))
					rv[id] = proto[id]
				
			rv.__native = arguments.callee.__native			
    	return rv	    			
		}
		catch(e) {
			jsl.throwError(e, this, arguments)
		}
	}
	//-------------------------------------------------------------------------------
	jsl.Number.__name 		= "jsl.Number"
	//-------------------------------------------------------------------------------
	jsl.Number.prototype 	= jsl.Object()	
	//-------------------------------------------------------------------------------
	jsl.Number.prototype.round	= function(d) {
		try {//@d[
			if(arguments.length > 1)	throw jsl.ParamError()
			if(!jsl.isNumber(this))		throw jsl.TypeError("BadMethodCall:Number")
			if(arguments.length)			jsl.validate(d, "i+", "d")//@d]
				
      return +this.toFixed(d || 0)
		}
		catch(e) {
			jsl.throwError(e, this, arguments)		
		}
	}
	//-------------------------------------------------------------------------------
	jsl.Number.prototype.ceil	= function(d) {
		try {
			var n
			//@d[			
			if(arguments.length > 1)	throw jsl.ParamError()
			if(!jsl.isNumber(this))		throw jsl.TypeError("BadMethodCall:Number")
			if(arguments.length)			jsl.validate(d, "i+", "d")//@d]
			 			
			if(d) {
	  		n = Math.pow(10, d)
  			n = Math.ceil(this * n) / n
 			}
			else 	
				n = Math.ceil(this)
			
  		return n
		}
		catch(e) {
			jsl.throwError(e, this, arguments)		
		}
	}
	//-------------------------------------------------------------------------------
	jsl.Number.prototype.floor	= function(d) {
		try {
			var n
			//@d[
			if(arguments.length > 1)	throw jsl.ParamError()
			if(!jsl.isNumber(this))		throw jsl.TypeError("BadMethodCall:Number")
			if(arguments.length)			jsl.validate(d, "i+", "d")//@d]
			 			
			if(d) {
	  		n = Math.pow(10, d)
  			n = Math.floor(this * n) / n
 			}
			else 	
				n = Math.floor(this)
			
  		return n
		}
		catch(e) {
			jsl.throwError(e, this, arguments)		
		}
	}
	//-------------------------------------------------------------------------------
	jsl.Number.prototype.limit	= function(max, min) {
		try {
			var n
			//@d[
			if(!arguments.length || arguments.length > 2)	throw jsl.ParamError()			
			if(!jsl.isNumber(this))												throw jsl.TypeError("BadMethodCall:Number")
			if(arguments.length)													jsl.validate(max, "N", "max")
			if(arguments.length === 2)										jsl.validate(min, "N", "min")						
			if(min != null && min > max)									throw jsl.ParamError("BadInterval:min > max")//@d]
			
			if(this > max)											n = max
			else if(min != null && this < min)	n = min
			else																n = this
			
			return +n
		}
		catch(e) {
			jsl.throwError(e, this, arguments)		
		}
	}
	//-------------------------------------------------------------------------------
	jsl.Number.prototype.toInteger	= function() {
		try {//@d[
			if(arguments.length)		throw jsl.ParamError()		
			if(!jsl.isNumber(this))	throw jsl.TypeError("BadMethodCall:Number")//@d]
			return ~~this
		}
		catch(e) {
			jsl.throwError(e, this, arguments)		
		}
	}
	//-------------------------------------------------------------------------------
	jsl.Number.prototype.isInteger	= function() {
		try {//@d[
			if(arguments.length)		throw jsl.ParamError()		
			if(!jsl.isNumber(this))	throw jsl.TypeError("BadMethodCall:Number")//@d]
			return !(this - ~~this)	
		}
		catch(e) {
			jsl.throwError(e, this, arguments)		
		}
	}
	//-------------------------------------------------------------------------------
	jsl.Number.random	= function(max, min) {
		try {			
			var m,n
			//@d[
			if(arguments.length > 2)		throw jsl.ParamError()			
			if(arguments.length)				jsl.validate(max, "n", "max")
			if(arguments.length === 2)	jsl.validate(min, "n", "min")//@d]		
			
			m = max != null ? max : 1
			n = min || 0
			//@d[			
			if(n > m)	throw jsl.ParamError("BadInterval:min > max")//@d]
      
      return n + Math.random() * (m - n)
		}
		catch(e) {
			jsl.throwError(e, this, arguments)		
		}
	}
	//-------------------------------------------------------------------------------
	jsl.Number.degToRad	= function(d) {
		try {//@d[
			if(arguments.length !== 1)	throw jsl.ParamError()			
      jsl.validate(d, "n", "d")//@d]
			
      return d * (2 * Math.PI) / 360
		}
		catch(e) {
			jsl.throwError(e, this, arguments)		
		}
	}
	//-------------------------------------------------------------------------------
	jsl.Number.radToDeg	= function(r) {
		try {//@d[
			if(arguments.length !== 1)	throw jsl.ParamError()		
      jsl.validate(r, "n", "r")//@d]	
			
      return r * 360 / (2 * Math.PI)
		}
		catch(e) {
			jsl.throwError(e, this, arguments)		
		}
	}
	//Number init
	//-------------------------------------------------------------------------------
	;(function() {
		
		var proto 
		
		//-------------------------------------------------------------------------------
		jsl.Number.__native	= jsl.Object.__native.copy().merge(jsl.Number.prototype)
		proto								= jsl.Number.prototype
			
		for(var id in proto) 
			if(proto.hasOwnProperty(id)) 
				if(id.charAt(0) !== "_" && jsl.isFunction(proto[id]) && !proto[id].__name) {
					
					jsl.Number[id] = function(obj) { 
						try {//@d[
							if(!arguments.length)	throw jsl.ParamError() 
							if(obj === null)			throw jsl.ParamError("NullValue:obj")//@d]
													
							return arguments.callee.__f.apply(obj, Array.prototype.slice.call(arguments, 1)) 
						}
						catch(e) {
							jsl.throwError(e, this, arguments)
						}
					}
				
					jsl.Number[id].__name	= id
					jsl.Number[id].__f		= proto[id]					
					proto[id].__name 			= id
				}			
	})()
  